﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace WebApplication7
{
    /// <summary>
    /// Summary description for ServiceNimic
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]

    public class ServiceNimic : System.Web.Services.WebService
    {
        static ServiceNimic instance;
        int[] diceNumbers = new int[4];
        String activePlayer;
        int activePlayerIndex = 0;
        int activePlayerFieldNumber = 0;

        public ServiceNimic()
        {
            for (int i = 0; i < 4; i++)
            {
                diceNumbers[i] = 0;
            }
        }

        public static ServiceNimic getInstance()
        {
            if (instance == null)
            {
                instance = new ServiceNimic();
            }
            return instance;
        }

        [WebMethod]
        public Boolean iRolledTheDice(int index, int value)
        {
            if ((value > 6) ||  (value < 1))
            {
                return false;
            }

            try
            {
                diceNumbers[index] = value;
            }
            catch
            {
                return false;
            }
            return true;
        }

        [WebMethod]
        public int getTheDiceNumber(int index)
        {
            if ((index >= 0) && (index <= 3))
            {
                int temp = diceNumbers[index];
                diceNumbers[index] = 0;
                return temp;
            }
            return 0;
        }

        [WebMethod]
        public int getActivePlayerIndex()
        {
            return activePlayerIndex;
        }

        [WebMethod]
        public void nextActivePlayerIndex()
        {
            activePlayerIndex++;
        }

        [WebMethod]
        public String getActivePlayer()
        {
            return activePlayer;
        }

        [WebMethod]
        public void setActivePlayer(String value)
        {
            activePlayer = value;
        }

        [WebMethod]
        public int getFieldNumber()
        {
            return activePlayerFieldNumber;
        }

        [WebMethod]
        public void setAPF(int value)
        {
            activePlayerFieldNumber = value;
        }
    }
}
